<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>定时任务后台管理页面</title>
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/css/animate.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/font-awesome.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/mediaelementplayer.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/red.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/simple-line-icons.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/style.css}"/>
</head>
<body>
<div class="col-md-12 top-20 padding-0">
    <div class="col-md-12">
        <div class="panel">
            <div class="panel-body">
                <div class="col-md-12 padding-0" style="padding-bottom:20px;">
                    <h2>定时任务列表</h2>
                    <hr/>
                    <div class="col-md-6" style="padding-left:10px;">
                        <form action="import" method="post">
                            <input type="button" class="btn  btn-raised btn-success" onclick="addNewTask()"
                                   value="新增定时任务"/>
                        </form>
                    </div>
                    <div class="col-md-6">
                        <div class="col-lg-12">
                            <form action="/index">
                                <div class="input-group">
                                    <input type="input" class="form-control" aria-label="..." name="name"/>
                                    <div class="input-group-btn">
                                        <input type="submit" class="btn  btn-raised btn-success" value="search"/>&nbsp;&nbsp;&nbsp;
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="responsive-table">
                    <table class="table table-striped table-bordered" width="100%" cellspacing="0" style="text-align:center;vertical-align:middle;">
                        <thead>
                        <tr>
                            <th style="text-align:center;vertical-align:middle;">任务编号</th>
                            <th style="text-align:center;vertical-align:middle;">任务名称</th>
                            <th style="text-align:center;vertical-align:middle;">定时配置cron</th>
                            <th style="text-align:center;vertical-align:middle;">冻结状态</th>
                            <th style="text-align:center;vertical-align:middle;">执行方</th>
                            <th style="text-align:center;vertical-align:middle;">执行方式</th>
                            <th style="text-align:center;vertical-align:middle;">创建时间</th>
                            <th style="text-align:center;vertical-align:middle;">最后修改时间</th>
                            <th style="text-align:center;vertical-align:middle;">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="task:${taskList}">
                            <td>
                                <a th:href="@{'/quartz/taskrecords?taskno='+${task.taskno}}" th:text="${task.taskno}"></a>
                            </td>
                            <td th:text="${task.taskname}"/>
                            <td th:text="${task.schedulerrule}"/>
                            <td>
                                <span th:if="${task.frozenstatus eq 'UNFROZEN'}">未冻结</span>
                                <span th:if="${task.frozenstatus eq 'FROZEN'}" style="color:red;">已冻结</span>
                            </td>
                            <td th:text="${task.executorno}"/>
                            <td>
                                <span th:if="${task.sendtype eq 'kafka'}">kafka</span>
                                <span th:if="${task.sendtype eq 'http'}">http</span>
                            </td>
                            <td th:text="${#dates.format(task.createtime,'yyyy-MM-dd HH:mm:ss')}"/>
                            <td th:text="${#dates.format(task.lastmodifytime,'yyyy-MM-dd HH:mm:ss')}"/>
                            <td>
                                <span th:if="${task.frozenstatus eq 'UNFROZEN'}"> <input type="button"
                                                                                         class="btn btn-3d btn-danger"
                                                                                         value="暂停"
                                                                                         th:onclick="'javascript:startOrStop('+${task.taskno}+')'"/>&nbsp;</span>
                                <span th:if="${task.frozenstatus eq 'FROZEN'}"> <input type="button"
                                                                                       class="btn  btn-3d btn-success"
                                                                                       value="启动"
                                                                                       th:onclick="'javascript:startOrStop('+${task.taskno}+')'"/>&nbsp;</span>
                                <input type="button" class="btn btn-3d btn-success"
                                       th:onclick="'javascript:runRightNow('+${task.taskno}+')'" value="立刻运行一次"/>
                                <input type="button" class="btn btn-3d btn-success"
                                       th:onclick="'javascript:editpage('+${task.id}+')'" value="修改"/>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="col-md-6" style="padding-top:20px;">
                    总共<span style="color: red;" th:text="${size}"/>条记录
                </div>

                <div class="col-md-6">
                    <ul class="pagination pull-right">
                        <li>
                            <a href="#" aria-label="Previous">
                                <span aria-hidden="true">上一页</span>
                            </a>
                        </li>
                        <li class="active">
                            <a href="#">1</a>
                        </li>
                        <li>
                            <a href="#">2</a>
                        </li>
                        <li>
                            <a href="#">3</a>
                        </li>
                        <li>
                            <a href="#">4</a>
                        </li>
                        <li>
                            <a href="#">5</a>
                        </li>
                        <li>
                            <a href="#" aria-label="Next">
                                <span aria-hidden="true">下一页</span>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" th:inline="javascript">
    function editpage(id) {
        location.href = "/quartz/edit/taskpage?id=" + id;
    }

    function addNewTask() {
        location.href = "/quartz/add/taskpage/";
    }

    function startOrStop(taskNo) {
        $.ajax({
            url: "/quartz/list/optionjob?taskNo=" + taskNo,
            type: "GET",
            dataType: "json",
            success: function (result) {
                if (result.code == 200) {
                    alert("success!");
                    location.href = "/";
                } else if (result.code == 6001) {
                    alert("任务编号为空!");
                } else if (result.code == 1003) {
                    alert("无此定时任务!");
                } else {
                    alert("system error!");
                }
            }
        });
    };

    function runRightNow(taskNo) {
        $.ajax({
            url: "/quartz/runtask/rightnow?taskno=" + taskNo,
            type: "GET",
            dataType: "json",
            success: function (result) {
                if (result.code == 200) {
                    alert("运行成功!");
                } else if (result.code == 6001) {
                    alert("任务编号不能为空!");
                } else if (result.code == 1003) {
                    alert("无此定时任务!");
                } else {
                    alert("执行失败!");
                }
            }
        });
    }
</script>
</body>
</html>
